package il.ac.tau.cvws.scrabblesidekick.client.ui;

import il.ac.tau.cvws.scrabblesidekick.client.app.controller.CalibrationController;
import il.ac.tau.cvws.scrabblesidekick.client.app.controller.ScrabbleSidekickController;
import il.ac.tau.cvws.scrabblesidekick.client.ui.constant.UserMessageConstant;
import il.ac.tau.cvws.scrabblesidekick.client.ui.service.UIServices;
import il.ac.tau.cvws.scrabblesidekick.client.ui.view.camera.CameraState;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.os.Bundle;
import android.view.View;

/* The calibration Android activity. It is the platform's controller, and is responsible
 * for orchestrating the calibration, displaying the UI and instructions.
 */
public class CalibrationActivity extends CameraActivity 
{ 
	@Override
    public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);

		buildCameraView();
		
		_state = CameraState.OFF;
		_cameraView.setVisibility(View.VISIBLE);
		
		UIServices.showDialog(this, "", UserMessageConstant.CALIBRATION_INSTRUCTIONS,
				  new OnCancelListener()
				  {
					  @Override
					  public void onCancel(DialogInterface dialog)
					  {
						  _state = CameraState.ON;						  
						  _cameraView.restart();				
					  }
				  });
	}
	
	/* On calibration success, show a success message and end the activity.
	 */
	@Override
	public void innerHandleSuccess()
	{
		_handler.hideProgressBar();
		
		UIServices.showDialog(this, "", UserMessageConstant.CALIBRATION_SUCCESS, new OnCancelListener()
		{
			@Override
			public void onCancel(DialogInterface dialog)
			{
				finish();
			}
		});
	}
	
	@Override
	protected ScrabbleSidekickController createController()
	{
		return new CalibrationController(this);
	}
}